package org.gd.hellojaxb.adapters;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.util.Currency;

/**
 * @author Gorhover
 */
public class CurrencyAdaptersContainer {

    /**
     * {@link XmlAdapter} for {@link Currency#getCurrencyCode()}
     * @author Gorhover
     */
    public static class CurrencyCode extends XmlAdapter<String, Currency> {

        /**
         * {@inheritDoc}
         */
        @Override
        public Currency unmarshal(String v) throws Exception {
            if(v == null || v.isEmpty()) {
                return null;
            }
            return java.util.Currency.getInstance(v);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String marshal(Currency v) throws Exception {
            if(v == null) {
                return null;
            }
            return v.getCurrencyCode();
        }
    }

    /**
     * {@link XmlAdapter} for {@link Currency#getNumericCode()}
     * @author Gorhover
     */
    public static class NumericCode extends XmlAdapter<Integer, Currency> {

        /**
         * {@inheritDoc}
         */
        @Override
        public Currency unmarshal(Integer v) throws Exception {
            if(v == null || v == 0) {
                return null;
            }
            return  null;


            //return java.util.Currency.getInstance(v);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public Integer marshal(Currency v) throws Exception {
            if(v == null) {
                return null;
            }
            return v.getNumericCode();
        }
    }
}
